package com.tiantian.quanminxiu.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;

import com.jakewharton.rxbinding.view.RxView;
import com.tiantian.quanminxiu.R;
import com.tiantian.quanminxiu.event.LiveRoomEvent;
import com.tiantian.quanminxiu.utils.APPUtils;
import com.tiantian.quanminxiu.utils.EventBusUtils;
import com.tiantian.quanminxiu.view.MvpView;
import com.tiantian.quanminxiu.wxapi.WXEntryActivity;

import cn.pedant.SweetAlert.SweetAlertDialog;
import rx.functions.Action1;

/**
 * Created by admin on 2016/9/14.
 */
public class Dialog_Share extends Dialog implements MvpView {

    private Activity activity;
    private int UserId;
    private String title;
    private String NickName;
    public View relMain;
    private View vShareQQ,vShareZone,vShareWeixin,vShareFriend,vShareWB;

    public Dialog_Share(Activity activity, int themeResId, int UserId, String NickName, String title) {
        super(activity, themeResId);
        this.activity = activity;
        this.UserId = UserId;
        this.NickName = NickName;
        this.title = title;
        InitView();
    }

    protected void InitView() {
        setContentView(R.layout.dialog_share);

        relMain = findViewById(R.id.relMain);
        vShareQQ = findViewById(R.id.vShareQQ);
        vShareZone = findViewById(R.id.vShareZone);
        vShareWeixin = findViewById(R.id.vShareWeixin);
        vShareFriend = findViewById(R.id.vShareFriend);
        vShareWB = findViewById(R.id.vShareWB);

        RxView.clicks(relMain).map(View -> relMain).subscribe(OC_Finish);
        RxView.clicks(vShareQQ).map(View->vShareQQ).subscribe(OC_Button);
        RxView.clicks(vShareZone).map(View->vShareZone).subscribe(OC_Button);
        RxView.clicks(vShareWeixin).map(View->vShareWeixin).subscribe(OC_Button);
        RxView.clicks(vShareFriend).map(View->vShareFriend).subscribe(OC_Button);
        RxView.clicks(vShareWB).map(View->vShareWB).subscribe(OC_Button);

    }

    //region 取消事件 OC_Finish
    public Action1<View> OC_Finish = v -> {
        dismiss();
    };
    //endregion

    public Action1<View> OC_Button = v->{
        switch (v.getId()){
            case R.id.vShareWeixin:
                WXEntryActivity.APPShare(activity,title,UserId,NickName,0);
                dismiss();
                break;
            case R.id.vShareFriend:
                WXEntryActivity.APPShare(activity, title,UserId, NickName, 1);
                dismiss();
                break;
            case R.id.vShareQQ:
                APPUtils.QQHelperLogin_To(activity,1,UserId,NickName,title);
                dismiss();
                break;
            case R.id.vShareZone:
                APPUtils.QQHelperLogin_To(activity, 2,UserId,NickName,title);
                dismiss();
                break;
            case R.id.vShareWB:
                APPUtils.SinaShare_To(activity,1,UserId,NickName,title);
                dismiss();
                break;
            case R.id.relMain:
                dismiss();
                break;
        }
    };

    @Override
    public void dismiss(){
        super.dismiss();
    }

    @Override
    public void Loading_Open() {

    }

    @Override
    public void Loading_Open(boolean flag) {

    }

    @Override
    public void Loading_Close() {

    }

}
